import Vue from "vue"
import Vuex from "vuex"
import commonModule from './commonModule'; // 引入 commonModule

Vue.use(Vuex)
let basedata = ""
let pooldata = ""
let baseblock = ""
let blockdata = ""
let fliedata = ""
let chosefile = ""
let chosepath = ""
let baseshare = ""
let basetips = ""
let tipslist = []
let tasklist = []
let lanflag = true
let basebucket = []
let timedata = {}
let islogin = ""
let language = "zh"
let taskflag = ""
let loginuser = ""
try {
	if (localStorage.taskflag) taskflag = JSON.parse(localStorage.taskflag)
	if (localStorage.basedata) basedata = JSON.parse(localStorage.basedata)
	if (localStorage.pooldata) pooldata = JSON.parse(localStorage.pooldata)
	if (localStorage.baseblock) baseblock = JSON.parse(localStorage.baseblock)
	if (localStorage.blockdata) blockdata = JSON.parse(localStorage.blockdata)
	if (localStorage.fliedata) fliedata = JSON.parse(localStorage.fliedata)
	if (localStorage.chosefile) chosefile = JSON.parse(localStorage.chosefile)
	// if (localStorage.chosepath)
	// 	chosepath=JSON.parse(localStorage.chosepath)
	if (localStorage.baseshare) baseshare = JSON.parse(localStorage.baseshare)
	if (localStorage.basetips) basetips = JSON.parse(localStorage.basetips)
	if (localStorage.tipslist) tipslist = JSON.parse(localStorage.tipslist)
	if (localStorage.tasklist) tasklist = JSON.parse(localStorage.tasklist)
	if (localStorage.basebucket) basebucket = JSON.parse(localStorage.basebucket)
	if (localStorage.timedata) timedata = JSON.parse(localStorage.timedata)
	if (localStorage.language) language = JSON.parse(localStorage.language)
	if (localStorage.lanflag) lanflag = JSON.parse(localStorage.lanflag)
	if (localStorage.loginuser) loginuser = JSON.parse(localStorage.loginuser)
} catch (e) { }

export default new Vuex.Store({
	state: {
		basedata: basedata,
		pooldata: pooldata,
		baseblock: baseblock,
		blockdata: blockdata,
		fliedata: fliedata,
		chosefile: chosefile,
		// chosepath:chosepath,
		baseshare: baseshare,
		basetips: basetips,
		tipslist: tipslist,
		tasklist: tasklist,
		lanflag: lanflag,
		basebucket: basebucket,
		timedata: timedata,
		islogin: islogin,
		language: language,
		taskflag: taskflag,
		loginuser: loginuser,
		cancelTokenArr: [], // 取消请求token数组
		isBlockListChange: false, // 判断是否块设备列表变化了，然后用来更新快照获取块设备(如：新增、克隆、删除块设备等)
		isRefreshBlockList: false, // 判断是否块设备列表变化了，然后更新块设备列表(如：快照克隆等)
		isUpdateUserList: false, //判断对象存储下是否新增了用户，然后更新桶下的所有者列表
		isUpdateSnapPath: false, //判断目录结构下的文件夹是否新增或删除，然后更新快照下获取的路径
		operOSDType: "",
		operOSDData: -1,
		isUpdateSysCollectRecord: false,
	},
	mutations: {
		islogin(state, msg) {
			state.islogin = msg.islogin
			localStorage.islogin = JSON.stringify(msg.islogin)
		},
		getlogin(state, msg) {
			state.loginuser = msg.loginuser
			localStorage.loginuser = JSON.stringify(msg.loginuser)
		},
		getlanguage(state, msg) {
			state.language = msg.language
			localStorage.language = JSON.stringify(msg.language)
		},
		lanflag(state, msg) {
			state.lanflag = msg.lanflag
			localStorage.lanflag = JSON.stringify(msg.lanflag)
		},
		indexmsg(state, msg) {
			state.basedata = msg.basedata
			localStorage.basedata = JSON.stringify(msg.basedata)
		},
		getpool(state, msg) {
			state.pooldata = msg.pooldata
			localStorage.pooldata = JSON.stringify(msg.pooldata)
		},
		getblock(state, msg) {
			state.baseblock = msg.baseblock
			localStorage.baseblock = JSON.stringify(msg.baseblock)
		},
		getblockdata(state, msg) {
			state.blockdata = msg.blockdata
			localStorage.blockdata = JSON.stringify(msg.blockdata)
		},
		getfiledata(state, msg) {
			state.fliedata = msg.fliedata
			localStorage.fliedata = JSON.stringify(msg.fliedata)
		},
		getchosefile(state, msg) {
			state.chosefile = msg.chosefile
			localStorage.chosefile = JSON.stringify(msg.chosefile)
		},
		// getchosepath(state,msg){
		// 	state.chosepath = msg.chosepath
		// 	localStorage.chosepath=JSON.stringify(msg.chosepath)
		// },
		getbaseshare(state, msg) {
			state.baseshare = msg.baseshare
			localStorage.baseshare = JSON.stringify(msg.baseshare)
		},
		getbasetips(state, msg) {
			state.basetips = msg.basetips
			localStorage.basetips = JSON.stringify(msg.basetips)
		},
		gettips(state, msg) {
			state.tipslist = msg.tipslist
			localStorage.tipslist = JSON.stringify(msg.tipslist)
		},
		gettasks(state, msg) {
			state.tasklist = msg.tasklist
			localStorage.tasklist = JSON.stringify(msg.tasklist)
		},
		getbasebucket(state, msg) {
			state.basebucket = msg.basebucket
			localStorage.basebucket = JSON.stringify(msg.basebucket)
		},
		gettimedata(state, msg) {
			state.timedata = msg.timedata
			localStorage.timedata = JSON.stringify(msg.timedata)
		},
		gettaskflag(state, msg) {
			state.taskflag = msg.taskflag
			localStorage.taskflag = JSON.stringify(msg.taskflag)
		},
		pushToken(state, payload) {
			state.cancelTokenArr.push(payload.cancelToken)
		},
		clearToken({ cancelTokenArr }) {
			cancelTokenArr.forEach((item) => {
				item("路由跳转取消请求")
			})
			// cancelTokenArr = [];
		},
		//更新获取快照页面下的块设备
		toGetBlockData(state, payload) {
			state.isBlockListChange = payload
		},
		//更新获取块设备列表
		toRefreshBlockList(state, payload) {
			state.isRefreshBlockList = payload
		},
		//更新对象存储桶下的所有者的接口数据
		toUpdateUsers(state, payload) {
			state.isUpdateUserList = payload
		},
		//目录结构下的文件夹更新后，快照下获取的路径更新
		toUpdateSnapPath(state, payload) {
			state.isUpdateSnapPath = payload
		},

		//跳转到OSD页面，同时获取要删除的几个OSD
		goToOsd(state, payload) {
			state.operOSDType = payload.type
			state.operOSDData = payload.currentData
		},

		//当收集系统日志后，更新系统日志收集记录
		updateCollectRecord(state, payload) {
			state.isUpdateSysCollectRecord = payload
		},
	},
	modules: {
		commonModule,  // 注册模块
	},
})
